﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using CourseDesign_02;

namespace FundamentalsOfCompiling
{
    class MidiatorOutput : Midiator
    {
        MainWindow window;

        public MidiatorOutput(MainWindow main)
        {
            window = main;
        }

        public MidiatorOutput()
        {
            // TODO: Complete member initialization
        }

        void Midiator.Write(TokenType token)
        {
            switch (token.Lex)
            {
                case LexType.PROGRAM:
                case LexType.PROCEDURE:
                case LexType.TYPE:
                case LexType.VAR:
                case LexType.IF:
                case LexType.THEN:
                case LexType.ELSE:
                case LexType.FI:
                case LexType.WHILE:
                case LexType.DO:
                case LexType.ENDWH:
                case LexType.BEGIN:
                case LexType.END:
                case LexType.READ:
                case LexType.WRITE:
                case LexType.ARRAY:
                case LexType.OF:
                case LexType.RECORD:
                case LexType.RETURN:
                case LexType.INTEGER:
                case LexType.CHAR1:
                    window.WriteLine("reserved word: " + token.Sem);
                    break;
                case LexType.ASSIGN: window.WriteLine(":="); break;

                case LexType.LT: window.WriteLine("<"); break;

                case LexType.EQ: window.WriteLine("="); break;

                case LexType.PLUS: window.WriteLine("+"); break;

                case LexType.MINUS: window.WriteLine("-"); break;

                case LexType.TIMES: window.WriteLine("*"); break;

                case LexType.OVER: window.WriteLine("/"); break;

                case LexType.LPAREN: window.WriteLine("("); break;

                case LexType.RPAREN: window.WriteLine(")"); break;

                case LexType.LMIDPAREN: window.WriteLine("["); break;

                case LexType.RMIDPAREN: window.WriteLine("]"); break;

                case LexType.SEMI: window.WriteLine(";"); break;

                case LexType.COLON: window.WriteLine(":"); break;

                case LexType.COMMA: window.WriteLine(","); break;

                case LexType.DOT: window.WriteLine("."); break;

                case LexType.UNDERANGE: window.WriteLine(".."); break;

                case LexType.ENDFILE1: window.WriteLine("EOF"); break;

                case LexType.INTC:
                    window.WriteLine("INTC, val= " + token.Sem);
                    break;

                case LexType.CHARC:
                    window.WriteLine("CHARC, letter= " + token.Sem);
                    break;

                case LexType.ID:
                    window.WriteLine("ID, name= " + token.Sem);
                    break;

                case LexType.ERROR1:
                    window.WriteLine("ERROR: " + token.Sem);
                    break;
                case LexType.CRT:
                    //window.WriteLine("记录的是换行符号..");
                    break;
                default:
                    window.WriteLine("Unknown token:" + token.Lex);
                    break;
            }
        }
    
        void Midiator.WriteLine(string str)
        {
            window.WriteLine(str);
        }

        void Midiator.Write(string str)
        {
            window.Write(str);
        }

    }
}
